package org.dbstar.scheduler.beans;

import java.io.Serializable;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.dbstar.scheduler.identifier.Identifier;


/**
 * Job的依赖项定义
 * 
 * @author 代波
 * @since 1.0.0
 * @version 1.0.0
 * @date 2012-5-2
 */
public class JobDependencyItem implements Serializable {
	private static final long serialVersionUID = -8468443951079967107L;

	private Identifier identifier;// Job定义标识
	private Boolean succeed;// Job执行结果是否成功
	private Map<String, String> parameters;// Job关键参数
	private String condition;// Job匹配条件

	public JobDependencyItem(Identifier identifier, Boolean succeed, Map<String, String> parameters, String condition) {
		super();
		setIdentifier(identifier);
		setSucceed(succeed);
		setParameters(parameters);
		setCondition(condition);
	}

	public JobDependencyItem() {
		super();
	}

	public Identifier getIdentifier() {
		return identifier;
	}

	public void setIdentifier(Identifier identifier) {
		this.identifier = identifier;
	}

	public Boolean getSucceed() {
		return succeed;
	}

	public void setSucceed(Boolean succeed) {
		this.succeed = succeed;
	}

	public int getParameterSize() {
		return parameters == null ? 0 : parameters.size();
	}

	public Map<String, String> getParameters() {
		return parameters;
	}

	public void setParameters(Map<String, String> parameters) {
		this.parameters = parameters == null || parameters.isEmpty() ? null : parameters;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = StringUtils.isBlank(condition) ? null : condition;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((condition == null) ? 0 : condition.hashCode());
		result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
		result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
		result = prime * result + ((succeed == null) ? 0 : succeed.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		JobDependencyItem other = (JobDependencyItem) obj;
		if (condition == null) {
			if (other.condition != null)
				return false;
		} else if (!condition.equals(other.condition))
			return false;
		if (identifier == null) {
			if (other.identifier != null)
				return false;
		} else if (!identifier.equals(other.identifier))
			return false;
		if (parameters == null) {
			if (other.parameters != null)
				return false;
		} else if (!parameters.equals(other.parameters))
			return false;
		if (succeed == null) {
			if (other.succeed != null)
				return false;
		} else if (!succeed.equals(other.succeed))
			return false;
		return true;
	}
}
